//
//  GHTabbarViewController.m
//  GodHorses
//
//  Created by coder on 2017/11/14.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "STTools_TabbarViewController.h"
#import "THHomeViewController.h"
#import "THCategoryHomeViewController.h"
#import "THMineViewController.h"
#import "THShopCarViewController.h"
#import "THTreeHoleHomeViewController.h"
#define didShowGuideKey @"didShowGuideKey"

@interface STTools_TabbarViewController ()<UITabBarControllerDelegate>
@property(nonatomic, strong) NSArray                     *imageArray;/**<  */
@property(nonatomic, strong) UIImageView                     *imageView;/**< <##> */
@property(nonatomic, assign) NSInteger                     index;/**<  */
@end

@implementation STTools_TabbarViewController
//
- (BOOL)prefersStatusBarHidden
{
    
    return self.selectedViewController.prefersStatusBarHidden;
}

- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
{
    return self.selectedViewController.preferredStatusBarUpdateAnimation;
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return self.selectedViewController.preferredStatusBarStyle;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        self.tabBar.backgroundColor = UIColor.whiteColor;
        self.tabBar.barTintColor =  UIColor.whiteColor;
        [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"Helvetica-Bold" size:11.f], NSForegroundColorAttributeName : UIColor.blackColor} forState:UIControlStateNormal];
        [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:STONEOBS_UI_THEME_BACKGROUNDCOLOR} forState:UIControlStateSelected];
        self.tabBar.backgroundImage = UIImage.new;
        [self.tabBar setShadowImage:UIImage.new];
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self stoneobs_fun_confiChildVC];
    self.delegate = self;
    [UITabBar appearance].translucent = YES;
    
}

- (void)stoneobs_fun_confiChildVC{

    [self stoneobs_fun_setTabbarChildController:[THHomeViewController new]
                         itemTitle:@"首页"
                         itemImage:[UIImage imageNamed:@"首页-n"]
                       selectImage:[UIImage imageNamed:@"首页-s"]
                           itemTag:10010];
    
    
    [self stoneobs_fun_setTabbarChildController:[THCategoryHomeViewController new]
                         itemTitle:@"商城"
                         itemImage:[UIImage imageNamed:@"商城"]
                       selectImage:[UIImage imageNamed:@"good_商城"]
                           itemTag:10010];
    
    
    UIImage * image = [[UIImage imageNamed:@"logo"] imageScaledToSize:CGSizeMake(25, 25)];
    [self stoneobs_fun_setTabbarChildController:[THTreeHoleHomeViewController new]
                         itemTitle:@"牛视界"
                         itemImage:image
                       selectImage:image
                           itemTag:10003];

    
    [self stoneobs_fun_setTabbarChildController:[THShopCarViewController new]
                         itemTitle:@"购物车"
                         itemImage:[UIImage imageNamed:@"购物车-n"]
                       selectImage:[UIImage imageNamed:@"购物车_s"]
                           itemTag:10003];
    
    [self stoneobs_fun_setTabbarChildController:[THMineViewController new]
                         itemTitle:@"我的"
                         itemImage:[UIImage imageNamed:@"我的"]
                       selectImage:[UIImage imageNamed:@"我的-s"]
                           itemTag:10003];

    self.selectedIndex = 2;
}

- (void)stoneobs_fun_setTabbarChildController:(UIViewController *)controller itemTitle:(NSString *)title itemImage:(UIImage *)image selectImage:(UIImage *)simage itemTag:(NSInteger)tag {
    

    simage = [simage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    RTRootNavigationController *navi = [[RTRootNavigationController alloc] initWithRootViewController:controller];
    navi.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image selectedImage:simage];
    navi.tabBarItem.tag = tag;
    [self addChildViewController:navi];
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    self.tabBar.hidden = NO;
}
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    return  YES;
}
@end

